package jheej5024_01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class SungJukDAO implements ISungJukDAO {

	private String DRV ="oracle.jdbc.driver.OracleDriver";
	private String URL = "jdbc:oracle:thin:jheej5024/jheej5024@112.216.253.125:1521:xe";
	private String insertSQL = "insert into SUNGJUK values(exam.nextval,?,?,?,?,?,?,?)";
	
	
	public boolean insertSungJuk(SungJukVO sv) {
		Connection conn = null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		boolean result = false;
		conn=openDataBase();
		
		try {
			pstmt=conn.prepareStatement(insertSQL);
			pstmt.setString(1,sv.getName());
			pstmt.setInt(2,sv.getKor());
			pstmt.setInt(3,sv.getEng());
			pstmt.setInt(4,sv.getMat());
			pstmt.setInt(5,sv.getTot());
			pstmt.setFloat(6,sv.getAvg());
			pstmt.setString(7,sv.getGrd());
			pstmt.executeUpdate();
			result=true;
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{closeDatabase(conn, pstmt, null);}
		
	
		
		return result;
	}

	private Connection openDataBase() {
		
		try {
			Class.forName(DRV);
		return	DriverManager.getConnection(URL);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	private void closeDatabase(Connection c, PreparedStatement p, ResultSet r) {
		if(r != null)try {r.close();r = null;}catch(Exception e) {}
		if(p != null)try {p.close();p = null;}catch(Exception e) {}
		if(c != null)try {c.close();c = null;}catch(Exception e) {}
		
	}
}
